Skip to content

Commit

Permalink
Testing: Modify InternalType utilities to handle None attributes
Browse files Browse the repository at this point in the history
This change does not affect the current functioning of the program,
as:
- _calc_external is only used in a context where self.internal exists
  and is a string
- _calc_internal is only used in a context where self.external exists

However, this change prevents typechecking errors once type annotations
are added, because:
- in _calc_external, self.internal.split fails if self.internal is not a
  string
- in _calc_internal, return self.external causes an error if the return
  type annotation is "str", because self.external might be None
  • Loading branch information
rdimaio committed Apr 26, 2024
1 parent 2c389be commit 3e0edd7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/rucio/common/types.py
Expand Up @@ -74,18 +74,20 @@ def __hash__(self):

def _calc_external(self):
''' Utility to convert between internal and external representations'''
split = self.internal.split('@', 1)
if len(split) == 1: # if cannot convert, vo is '' and this is single vo
vo = 'def'
external = split[0]
else:
vo = split[1]
external = split[0]
return vo, external
if isinstance(self.internal, str):
split = self.internal.split('@', 1)
if len(split) == 1: # if cannot convert, vo is '' and this is single vo
vo = 'def'
external = split[0]
else:
vo = split[1]
external = split[0]
return vo, external
return '', ''

def _calc_internal(self):
''' Utility to convert between internal and external representations'''
if self.vo == 'def':
if self.vo == 'def' and self.external is not None:
return self.external
internal = '{}@{}'.format(self.external, self.vo)
return internal
Expand Down

0 comments on commit 3e0edd7

Please sign in to comment.