ahawker / ulid

Universally Unique Lexicographically Sortable Identifier (ULID) in Python 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with using ulid with `mypy --strict`

kolomenkin opened this issue · comments

Hi,
my project is using mypy --strict.
While importing ulid I'm getting a problem:

import ulid

MY_ULID = ulid.new()
error: Module has no attribute "new"

I found a workaround:

import ulid

MY_ULID = ulid.api.new()

But I'm sure the first way is a bit more preferable.

Investigation

I made some investigation on the problem.
The following modified content of __init__.py should fix the problem:

from .api import from_bytes, from_int, from_randomness, from_str, from_timestamp, from_uuid, new, parse
from .ulid import Randomness, Timestamp, ULID


__all__ = [
    # from .api
    'new', 'parse', 'from_bytes', 'from_int', 'from_str', 'from_uuid', 'from_timestamp', 'from_randomness',
    # from .ulid
    'Timestamp', 'Randomness', 'ULID',
]

__version__ = '0.0.14' 

So I explicitly imported items and explicitly listed them in __all__ . This is some code duplication, but it looks not fatal for me.

Questions

Q1. Should I create PR with the these changes for in __init__.py?

Q2. Should I crate PR to fix all mypy --strict errors for the whole ulid project? The fixes are going to be trivial from my experience. Here is the full list of mypy errors:

ulid\ulid.py:23: error: Function is missing a type annotation
ulid\ulid.py:26: error: Function is missing a type annotation
ulid\ulid.py:39: error: Function is missing a type annotation
ulid\ulid.py:52: error: Function is missing a type annotation
ulid\ulid.py:67: error: Function is missing a type annotation
ulid\ulid.py:82: error: Function is missing a type annotation
ulid\ulid.py:97: error: Function is missing a type annotation
ulid\ulid.py:112: error: Function is missing a return type annotation
ulid\ulid.py:115: error: Function is missing a return type annotation
ulid\ulid.py:118: error: Function is missing a return type annotation
ulid\ulid.py:121: error: Function is missing a return type annotation
ulid\ulid.py:124: error: Function is missing a return type annotation
ulid\ulid.py:127: error: Function is missing a return type annotation
ulid\ulid.py:275: error: Returning Any from function declared to return "Timestamp"
ulid\ulid.py:275: error: Call to untyped function "Timestamp" in typed context
ulid\ulid.py:284: error: Returning Any from function declared to return "Randomness"
ulid\ulid.py:284: error: Call to untyped function "Randomness" in typed context
ulid\api.py:47: error: Returning Any from function declared to return "ULID"
ulid\api.py:47: error: Call to untyped function "ULID" in typed context
ulid\api.py:104: error: Returning Any from function declared to return "ULID"
ulid\api.py:104: error: Call to untyped function "ULID" in typed context
ulid\api.py:124: error: Returning Any from function declared to return "ULID"
ulid\api.py:124: error: Call to untyped function "ULID" in typed context
ulid\api.py:137: error: Returning Any from function declared to return "ULID"
ulid\api.py:137: error: Call to untyped function "ULID" in typed context
ulid\api.py:149: error: Returning Any from function declared to return "ULID"
ulid\api.py:149: error: Call to untyped function "ULID" in typed context
ulid\api.py:198: error: Returning Any from function declared to return "ULID"
ulid\api.py:198: error: Call to untyped function "ULID" in typed context
ulid\api.py:244: error: Returning Any from function declared to return "ULID"
ulid\api.py:244: error: Call to untyped function "ULID" in typed context

@kolomenkin Thanks for the report and apologies for the issue.

I wasn't seeing any of the reported issues that you listed above in ulid/api.py. Possible a difference in mypy version or when it's run vs. referenced as a lib? Not sure.

In any case, I believe I've addressed this in my PR. You can build from source to test if needed; otherwise I should have a new patch version out relatively soon with these changes.

Please reopen if you still experience these issues with those changes.

Reopening; I've found a way to reproduce the additional errors in strict mode.