Skip to content

stricter checking of types #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Oct 21, 2017
Merged

stricter checking of types #131

merged 32 commits into from
Oct 21, 2017

Conversation

igalic
Copy link
Collaborator

@igalic igalic commented Sep 24, 2017

This patchset addresses #39.

we've now added the entire (default) config of flake8-mypy.
The following options deviate from their default (which gets us a step
closer to mypy --strct)

  • ignore_missing_imports=False
  • follow_imports=True
  • cache_dir=.mypy_cache
  • disallow_untyped_calls=True
  • warn_return_any=True

We've also toggled these two:

  • warn_redundant_casts=True
  • warn_unused_ignores=True

Finally, we check for

  • check_untyped_defs=True

For the full --strict set, we'd also need:

  • disallow_untyped_defs=True

But that, we'll need better typedefs.

@igalic igalic force-pushed the chore/mypy-strict branch 3 times, most recently from 9863289 to 39f9f21 Compare September 30, 2017 18:43
igalic added a commit that referenced this pull request Oct 3, 2017
the consequence of this is that we need to declare the non-existent
function destroy in `Resource`.
As a consequence, we have to explicitly declare it in the slightly
specialized classes that directly inherit from it, `DefaultResource`
and `ListableResource`. We "implement" it by raising an error.

This patch fixes #156, and has been once again discovered by `mypy
--strict` (#131).
gronke pushed a commit that referenced this pull request Oct 3, 2017
the consequence of this is that we need to declare the non-existent
function destroy in `Resource`.
As a consequence, we have to explicitly declare it in the slightly
specialized classes that directly inherit from it, `DefaultResource`
and `ListableResource`. We "implement" it by raising an error.

This patch fixes #156, and has been once again discovered by `mypy
--strict` (#131).
@igalic igalic force-pushed the chore/mypy-strict branch from 39f9f21 to b9a5886 Compare October 4, 2017 22:26
@igalic
Copy link
Collaborator Author

igalic commented Oct 5, 2017

issues (in mypy) discovered:

possible candidates:

for errors such as:

iocage/cli/destroy.py:44: error: Incompatible types in assignment (expression has type None, variable has type "Terms")

in a function definition like:

def cli(ctx,
        force: bool=False,
        release: bool=False,
        recursive: bool=False,
        download: bool=False,
        filters: iocage.lib.Filter.Terms=None) -> None:

filters will incorrectly be recognized as Terms, rather than Optional[Terms]

@gronke
Copy link
Member

gronke commented Oct 5, 2017

filters will incorrectly be recognized as Terms, rather than Optional[Terms]

Don't you have to specify that? Like such

def cli(ctx,
        force: bool=False,
        release: bool=False,
        recursive: bool=False,
        download: bool=False,
        filters: typing.Optional[iocage.lib.Filter.Terms]=None) -> None:

@igalic
Copy link
Collaborator Author

igalic commented Oct 5, 2017

yup, according to the Python Zen, explicit is better than implicit. As such, mypy will be removing implicit Optional (thru None assignment) and --strict) already enforces that.

@igalic igalic force-pushed the chore/mypy-strict branch from 14af576 to da3d615 Compare October 5, 2017 12:27
@igalic igalic force-pushed the chore/mypy-strict branch from d1d42e5 to 4c3768e Compare October 6, 2017 19:18
@gronke gronke force-pushed the chore/mypy-strict branch 2 times, most recently from 89101ce to a6e6508 Compare October 8, 2017 21:01
@igalic igalic force-pushed the chore/mypy-strict branch from 1dab5e5 to 9a17bca Compare October 11, 2017 07:16
@gronke gronke mentioned this pull request Oct 20, 2017
@gronke gronke force-pushed the chore/mypy-strict branch 5 times, most recently from e0a4389 to f4eea17 Compare October 21, 2017 18:37
Copy link
Collaborator Author

@igalic igalic left a comment

Choose a reason for hiding this comment

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

some questions

@@ -142,6 +144,7 @@ def get_command(self, ctx, name):
pass
return mod.cli
except (ImportError, AttributeError):
raise
return
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what?

Copy link
Member

Choose a reason for hiding this comment

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

I need to add a --develop flag or something similar. This swallows code errors, which is okay for runtime, but hell for development. This is why it always re-appears here until I rebase a branch for merging.

@@ -75,3 +100,59 @@ def cli(ctx, rc, log_level, force, jails):
jails_input = " ".join(list(jails))
logger.error(f"No jails matched your input: {jails_input}")
exit(1)


def normal(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what's normal anyway?

Copy link
Member

Choose a reason for hiding this comment

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

not autostart

@@ -118,7 +118,7 @@ class JailConfigDefaults(iocage.lib.Config.Jail.BaseConfig.BaseConfig):

def __init__(
self,
logger: 'iocage.lib.Logger.Logger'=None
logger: typing.Optional['iocage.lib.Logger.Logger']=None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

@@ -104,17 +100,17 @@ class Fstab(list, iocage.lib.Config.Jail.File.Prototype.ResourceConfigFile):
"""
AUTO_COMMENT_IDENTIFIER = "iocage-auto"

release: 'iocage.lib.Release.ReleaseGenerator'
release: typing.Optional['iocage.lib.Release.ReleaseGenerator']
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

host: 'iocage.lib.Host.HostGenerator'=None
release: typing.Optional['iocage.lib.Release.ReleaseGenerator']=None,
logger: typing.Optional['iocage.lib.Logger.Logger']=None,
host: typing.Optional['iocage.lib.Host.HostGenerator']=None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

def _update_freebsd_jail(
self,
jail: 'iocage.lib.Jail.JailGenerator'
) -> typing.Generator['iocage.lib.events.IocageEvent', None, None]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

self,
update: typing.Optional[bool]=None,
fetch_updates: typing.Optional[bool]=None
) -> typing.List['iocage.lib.events.IocageEvent']:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?


def update( # noqa: T484
self
) -> typing.List['iocage.lib.events.IocageEvent']:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

safe_mode: bool=True,
logger: 'iocage.lib.Logger.Logger'=None
logger: typing.Optional['iocage.lib.Logger.Logger']=None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

def clone_release(self, release):
def clone_release(
self,
release: 'iocage.lib.Release.ReleaseGenerator'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this a forward declaration?

@igalic
Copy link
Collaborator Author

igalic commented Oct 21, 2017

@gronke could you also explain the str(foo) here?

@igalic igalic force-pushed the chore/mypy-strict branch from 12bae38 to 9328f82 Compare October 21, 2017 21:00
@gronke gronke merged commit c4228df into master Oct 21, 2017
@gronke gronke deleted the chore/mypy-strict branch October 21, 2017 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants