Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions acclimatise/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,21 @@ def _name_from_arg(self) -> typing.Iterable[str]:

def get_type(self) -> cli_types.CliType:
# Try the argument name, then the flag name, then the description in that order
arg_type = self.args.get_type()
if arg_type is not None:
return arg_type

flag_type = infer_type(self.full_name())
if flag_type is not None:
return flag_type

return infer_type(self.description) or cli_types.CliString()
tpe = None
tpe_cand = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer descriptive variable names where possible. typ and type_candidates please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have though your example in #37 would predict None, then CliFile() then CliFile() respectively, and then return CliFile(). We only use subclasses for CliFileSystemType, and only recently, but the inference will never return CliFileSystemType, so it seems irrelevant.

True. I already forgot that we implemented the distinction between in/output files/dirs by properties and not subclasses.Then I will check for isinstance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that makes more sense

self.args.get_type(),
infer_type(self.full_name()),
infer_type(self.description),
cli_types.CliString()
]
for c in tpe_cand:
if tpe is None:
if c is not None:
tpe = c
else:
if issubclass(c, tpe):
tpe = c
return tpe

def full_name(self) -> str:
"""
Expand Down