profile
viewpoint

dropbox/pyannotate 1046

Auto-generate PEP-484 annotations

dropbox/sqlalchemy-stubs 179

Mypy plugin and stubs for SQLAlchemy

gvanrossum/pyxl3 105

A Python 3 extension for writing structured and reusable inline HTML.

msullivan/LazyK 11

Updated LazyK source distribution

JukkaL/mypy-website 10

Source code for the mypy web site

msullivan/godels-t 6

Formalization of a bunch of properties of Godel's System T in agda

jwise/minilib 3

A small C library that one might wish to plop down in bare-metal projects.

msullivan/advent-of-code 3

my advent of code solutions

msullivan/cmd-queue 3

A really dumb script for running a queue of commands

msullivan/agda-lib 2

A standard library for Agda (mirror of BitBucket repository)

push eventpython/mypy

Shantanu

commit sha 6efbff4b7c69ee0104a11a5e3f0360921f460358

stubtest: workaround mypyc (#8411)

view details

push time in 2 hours

PR merged python/mypy

stubtest: workaround mypyc's issue with vars

Follow up from #8380

Thanks for the fix! The cast works, but unfortunately we have one last issue: mypyc does not like the conditional definitions necessary to work around a bug in Python 3.5.2 and earlier (https://github.com/python/mypy/pull/8380/commits/8fda109d6b07a23670cc1148155e4696d94654e0). Example stacktrace here: https://travis-ci.org/hauntsaninja/mypy/jobs/651008763 Long story short, this PR doesn't do anything, but maybe it will in the future!

+4 -3

0 comment

2 changed files

hauntsaninja

pr closed time in 2 hours

issue commentpython/typed_ast

typed_ast.ast27 crashes on coding declarations

(I know mypy handles coding declarations itself and passes a str to typed_ast. )

On Thu, Feb 13, 2020, 11:44 Guido van Rossum notifications@github.com wrote:

Confirmed, and also confirmed that the stdlib ast module doesn't have this problem (in Python 3.7, 3.8 and in Python 2.7). Ironically, passing it a Unicode string with an encoding declaration doesn't trigger this error.

(I wouldn't call it a crash though. It's reporting a SyntaxError.)

@r3m0t https://github.com/r3m0t, do you feel up to trying to coming up with a fix?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/python/typed_ast/issues/133?email_source=notifications&email_token=AACTC7LNLBZTMCTAZGC5JBDRCWPJTA5CNFSM4KUP2JU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELWLM4Y#issuecomment-585938547, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACTC7JM6WXBJKCE47PSNVDRCWPJTANCNFSM4KUP2JUQ .

r3m0t

comment created time in 5 days

pull request commentpython/mypy

stubtest: add tests

Sorry, I had meant to double back on this and it slipped through the cracks. __dict__ is going to have trouble, since compiled objects don't have them. We do some hacks such as https://github.com/python/mypy/blob/master/mypy/util.py#L312-L321 to deal with some of these issues. mypyc compiled objects also all have a __getstate__ method that will return a dictionary.

mypyc really needs to implement a system for overriding lies in typeshed (as discussed https://github.com/mypyc/mypyc/issues/676).

I think the workaround here would be to do cast(Any, vars)(runtime). Casting the return of vars is too late, since mypyc will have already checked that it matches the original type.

If you want to follow-up with another attempt to get it to work, I'll review it quickly. But it isn't particularly critical.

hauntsaninja

comment created time in 6 days

delete branch python/mypy

delete branch : fix-it-again

delete time in 6 days

push eventpython/mypy

Michael J. Sullivan

commit sha 770276d70c3892f4154be85b96ec028705941184

Actually fix the api curses crash. (#8396) I refactored after I tested, which was a mistake.

view details

push time in 6 days

PR merged python/mypy

Actually fix the api curses crash.

I refactored after I tested, which was a mistake.

+6 -3

0 comment

1 changed file

msullivan

pr closed time in 6 days

create barnchpython/mypy

branch : fix-it-again

created branch time in 6 days

PR opened python/mypy

Actually fix the api curses crash.

I refactored after I tested, which was a mistake.

+6 -3

0 comment

1 changed file

pr created time in 6 days

delete branch python/mypy

delete branch : fix-dmypy-api

delete time in 7 days

push eventpython/mypy

Michael J. Sullivan

commit sha 9ff569cfc43a2931cc4e7d3b84a0f0f85f59d565

Fix initialize_unix_colors when sys.stdout is overridden with a TextIO (#8388)

view details

push time in 7 days

push eventpython/mypy

Michael J. Sullivan

commit sha 7680cf09ee08afbc2e902dbe9fd0ceb6009b88bf

kick

view details

push time in 7 days

pull request commentpython/mypy

mypy: attempt to fix build

Thanks for looking at this. That is very annoying.

hauntsaninja

comment created time in 8 days

create barnchpython/mypy

branch : fix-dmypy-api

created branch time in 8 days

issue commentpython/mypy

Dict comprehensions fail in NamedTuple

Moving out below the namedtuple also makes it work. That is deeply weird.

Some semantic analyzer weirdness I think.

edward-io

comment created time in 8 days

pull request commentpython/mypy

mypy: require Python 3.5.3 or greater

We could drop 3.5.1 support but I dropping 3.5.2 support is a nonstarter. We still (unfortunately) run mypy with 3.5.2 in some places. Ubuntu 16.04.6 has 3.5.2. I don't really mind dropping stubtest support though in 3.5.2?

hauntsaninja

comment created time in 8 days

push eventpython/mypy

Marcio Mazza

commit sha dca8489ba70f838d7f9f1b6cb322fcf7c9dad1b3

Add Tuples of variable size to the cheat sheet (#8364)

view details

push time in 8 days

PR merged python/mypy

Add Tuples of variable size to the cheat sheet
+4 -1

0 comment

1 changed file

marciomazza

pr closed time in 8 days

pull request commentpython/mypy

Analyze descriptor methods as if they're methods, not functions

This seems reasonable and I'm happy to merge it. Can a test be written, though?

janverb

comment created time in 8 days

issue closedpython/mypy

Bug if use async init pattern

from typing import Dict
from typing import Optional


class A:
    def __init__(self):
        self.var: Optional[Dict[str, str]] = None

    async def _init(self):
        # Do some work
        self.var = {}

    async def get(self, key) -> str:
        if self.var is None:
            await self._init()

        return self.var[key]

Error

test.py:17: error: Value of type "Optional[Dict[str, str]]" is not indexable
Found 1 error in 1 file (checked 1 source file)

closed time in 11 days

heckad

issue commentpython/mypy

Bug if use async init pattern

The same thing happens even without async, and is for better or worse just how mypy is. I don't think we're going to track which methods change types and process that.

Is it particularly worse in the async case?

heckad

comment created time in 11 days

issue closedpython/mypy

Using Callable as a member variable of a class Protocol fails

I'm not sure if this is a bug or I just don't know the proper incantation. I am trying to define a class that implements a Protocol having a member function which is a callable. The code looks like this:

sample.py:

from dataclasses import dataclass, field
from typing import List, Any, Callable
from typing_extensions import Protocol

class TaskFactory(Protocol):
    def __call__(self, strs: List[str]) -> Any:
        ...

class TaskSpec(Protocol):
    factory: TaskFactory
    strs: List[str] = field(default_factory=list)

@dataclass
class TaskSpecAdapter:
    factory: TaskFactory
    strs: List[str] = field(default_factory=list)

class NewStyleTask:

    strs: List[str] = ['pick-cam']

    def factory(self, strs: List[str]) -> Any:
        # no op
        pass

specA: TaskSpec = TaskSpecAdapter(
    lambda strs: 'noop'
)
specB: TaskSpec = NewStyleTask()

mypy sample.py fails with this:

sample.py:30: error: Incompatible types in assignment (expression has type "NewStyleTask", variable has type "TaskSpec")
sample.py:30: note: Protocol member TaskSpec.factory expected settable variable, got read-only attribute

searching for the expected settable variable error I found https://github.com/python/typing/issues/622, but when I added @property to the TaskSpec.factory definition, I get an invalid syntax error.

How do I define a member function of a class to implement a callable of a Protocol?

closed time in 11 days

jbcpollak

issue commentpython/mypy

Using Callable as a member variable of a class Protocol fails

To make it a property, you need to write

    @property
    def factory(self) -> TaskFactory:
        pass

That should work.

jbcpollak

comment created time in 11 days

issue commentpython/mypy

get_dynamic_class_hook() not invoked on generic types

I'd be happy to review a PR if you send one!

mkurnikov

comment created time in 11 days

issue commentpython/mypy

Segmentation fault with custom TypeTraverserVisitor

Could you try to produce a standalone test case for me to run somehow?

mkurnikov

comment created time in 11 days

push eventpython/mypy

Jan Verbeek

commit sha d6c2c01fd04043bff55222f1f43a9fe2e15c0ccf

Support determining whether a literal is truthy (#8368) This means types like Union[Literal[False], str] can be narrowed down more easily.

view details

push time in 11 days

PR merged python/mypy

Support determining whether a literal is truthy

This means types like Union[Literal[False], str] can be narrowed down more easily.

One test had to be adjusted, because it started checking more aggressively whether a union could be simplified. I think that's ok, because it's doing the equivalent of simplifying Union[Literal["foo"], str] to str, which seems correct.

+29 -4

0 comment

3 changed files

janverb

pr closed time in 11 days

push eventpython/mypy

Xuanda Yang

commit sha 3bd6e47f53e5ab09e30d7065e91d744fbc0821e3

Fix covariant overriding of decorated methods (#8350) Fixes #5836.

view details

push time in 11 days

PR merged python/mypy

Reviewers
Allow covariance for read-only attributes

resolves #5836

For now, I've not added any tests yet. I've tested against code samples in #5836 and #3260 and the patch is working but adding either of them seems to require modifying a lot in test fixtures

The new helper function is_writable_attribute is actually borrowed from check_no_writable. I'd also like to refactor the latter function's name and implement it using the new helper in this PR, since I think its name is kind of misleading considering the comments https://github.com/python/mypy/blob/ea3c65cc377fcb6e810dec9ed6314b25113dcda2/mypy/checker.py#L2391-L2402

+48 -13

2 comments

2 changed files

TH3CHARLie

pr closed time in 11 days

issue closedpython/mypy

Decorated method type-incompatibility with superclass

I'm raising a bug.

It's also posted on SO at https://stackoverflow.com/q/52744713/5986907

I get

$ mypy file.py
python.py:34: error: Signature of "fn" incompatible with supertype "B"

for file.py

from typing import Callable, TypeVar, cast

T = TypeVar('T')


def dec(f: Callable[..., T]) -> T:
    def p(self):
        return getattr(self, '_' + f.__name__)

    return cast(T, property(p))


class X:
    pass


class Y(X):
    pass


class A:
    _fn = Y()


class B(A):
    @dec
    def fn(self) -> X:
        return X()


class C(B):
    @dec
    def fn(self) -> Y:
        return Y()

I'd expect there to be no error as Y is a subclass of X.

I've tried this with mypy 0.630 and Python 3.5.2, 3.6.6 and 3.7.0. Also with mypy git master for python 3.5.2 and 3.7.0

It's possible these are related but I couldn't quite connect them https://github.com/python/mypy/issues/220 https://github.com/python/mypy/issues/4430

closed time in 11 days

joelberkeley

issue closedpython/mypy

mypy doesn't understand if with and

Bug Code to reproduce: https://mypy-play.net/?mypy=latest&python=3.8&gist=119ad8a52e4c5eae1cb9acdca7b5dc25.

Actual behaviour: mypy compains that b can be None.

Expected behaviour: mypy should accept this code because b can't be None as checked in line 4.

closed time in 11 days

GoldsteinE

issue commentpython/mypy

mypy doesn't understand if with and

This requires a much more elaborate system of predicate and control flow tracking than we are likely to support. Sorry!

GoldsteinE

comment created time in 11 days

push eventpython/mypy

Shantanu

commit sha c059437858a917d25bf07724d75489160385daed

mypy self check: add python_version = 3.5 (#8382)

view details

push time in 11 days

PR merged python/mypy

mypy self check: add python_version = 3.5

This would have helped me catch some variable annotations sooner.

+1 -0

0 comment

1 changed file

hauntsaninja

pr closed time in 11 days

delete branch python/mypy

delete branch : fix-incremental-adhoc-intersect

delete time in 11 days

push eventpython/mypy

Michael J. Sullivan

commit sha e06180223ddb0da34ea224761c873705f2ab4f2e

Fix an incremental crash bug caused by ad-hoc intersection (#8381) Ad-hoc intersection was generating type names with dots in them, which are interpreted as module separators. I fixed this by making the names worse and just using the bare name of the class. There are other options that could be pursued: * Replacing "." with some other character and then either switching it back when displayed or just printing it. One option that I was very tempted by was to use U+2024 ONE DOT LEADER. * Compute the intersection names on the fly when formatting. I decided to do the most obvious and the least tricky thing because this isn't important.

view details

push time in 11 days

PR merged python/mypy

Fix an incremental crash bug caused by ad-hoc intersection

Ad-hoc intersection was generating type names with dots in them, which are interpreted as module separators. I fixed this by making the names worse and just using the bare name of the class.

There are other options that could be pursued:

  • Replacing "." with some other character and then either switching it back when displayed or just printing it. One option that I was very tempted by was to use U+2024 ONE DOT LEADER.
  • Compute the intersection names on the fly when formatting.

I decided to do the most obvious and the least tricky thing because this isn't important.

+54 -8

0 comment

4 changed files

msullivan

pr closed time in 11 days

create barnchpython/mypy

branch : fix-incremental-adhoc-intersect

created branch time in 11 days

PR opened python/mypy

Fix an incremental crash bug caused by ad-hoc intersection

Ad-hoc intersection was generating type names with dots in them, which are interpreted as module separators. I fixed this by making the names worse and just using the bare name of the class.

There are other options that could be pursued:

  • Replacing "." with some other character and then either switching it back when displayed or just printing it. One option that I was very tempted by was to use U+2024 ONE DOT LEADER.
  • Compute the intersection names on the fly when formatting.

I decided to do the most obvious and the least tricky thing because this isn't important.

+54 -8

0 comment

4 changed files

pr created time in 11 days

push eventpython/mypy

Jakub Stasiak

commit sha 8888b1aedf6d4ba543ae12f538f190ce5e65c20d

Support typing.Annotated on top of typing_extensions.Annotated (#8371) This is to handle PEP 593 support recently merged into CPython[1]. [1] https://github.com/python/cpython/pull/18260

view details

push time in 12 days

PR merged python/mypy

Support typing.Annotated on top of typing_extensions.Annotated

This is to handle PEP 593 support recently merged into CPython[1].

I'm wondering what to do with this test-wise, as https://github.com/python/mypy/blob/39d6bde2ec7063bd2cec42cce9295479e744bcc7/test-data/unit/check-annotated.test is full of imports from typing_extensions and ideally, when running mypy tests on CPython nightly, tests would also import Annotated from typing. But maybe it's not worth it right now.

[1] https://github.com/python/cpython/pull/18260

+2 -1

0 comment

1 changed file

jstasiak

pr closed time in 12 days

pull request commentpython/mypy

Add a section for incompatible overrides

Is there a simpler example that could be used, without TypedDicts? Ideally using built-in types?

rahulrj

comment created time in 12 days

push eventpython/mypy

Michael J. Sullivan

commit sha a6c45093d0475cb3bb13b28df448a27abf6a96fb

Use repr to format out/err in dmypy verbose stats output (#8374) This prevents control characters being interpreted, though it does uglify the output in its own way.

view details

push time in 12 days

delete branch python/mypy

delete branch : dmypy-verbose-cleanup

delete time in 12 days

PR merged python/mypy

Use repr to format out/err in dmypy verbose stats output

This prevents control characters being interpreted, though it does uglify the output in its own way.

+1 -1

0 comment

1 changed file

msullivan

pr closed time in 12 days

delete branch python/mypy

delete branch : dmypy-api

delete time in 13 days

push eventpython/mypy

Michael J. Sullivan

commit sha 0c0369069c547feb5ccf43c886fcafafd87f476a

Make mypy.api.run_dmypy actually capture the output (#8375) When the main run API was made threadsafe this broke output capturing from run_dmypy. I don't really care about the threadsafety of run_dmypy but I do care about output capture ever working, so I am restoring the old sys.stdout swapping behavior for run_dmypy. I'd take a patch to thread stdout through the client if anybody really cares.

view details

push time in 13 days

PR merged python/mypy

Make mypy.api.run_dmypy actually capture the output

When the main run API was made threadsafe this broke output capturing from run_dmypy. I don't really care about the threadsafety of run_dmypy but I do care about output capture ever working, so I am restoring the old sys.stdout swapping behavior for run_dmypy. I'd take a patch to thread stdout through the client if anybody really cares.

+21 -2

1 comment

1 changed file

msullivan

pr closed time in 13 days

pull request commentpython/typeshed

subprocess: Make stdin, stdout & stderr Optional for py3 to match py2

Hm, maybe I don't actually care with Popen. I do care about it for subprocess.CompleteProcess, see: https://github.com/python/typeshed/blob/6394c7c335507b16b04b693cbcb10baa6670f511/stdlib/3/subprocess.pyi#L46-L49

JasonGilholme

comment created time in 13 days

pull request commentpython/mypy

Make mypy.api.run_dmypy actually capture the output

Yeah. When I went to do that, I discovered that our wrapper scripts were already trying to silence those messages, it just didn't work.

msullivan

comment created time in 13 days

create barnchpython/mypy

branch : dmypy-api

created branch time in 13 days

PR opened python/mypy

Make mypy.api.run_dmypy actually capture the output

When the main run API was made threadsafe this broke output capturing from run_dmypy. I don't really care about the threadsafety of run_dmypy but I do care about output capture ever working, so I am restoring the old sys.stdout swapping behavior for run_dmypy. I'd take a patch to thread stdout through the client if anybody really cares.

+21 -2

0 comment

1 changed file

pr created time in 13 days

PR opened python/mypy

Use repr to format out/err in dmypy verbose stats output

This prevents control characters being interpreted, though it does uglify the output in its own way.

+1 -1

0 comment

1 changed file

pr created time in 13 days

create barnchpython/mypy

branch : dmypy-verbose-cleanup

created branch time in 13 days

pull request commentpython/typeshed

subprocess: Make stdin, stdout & stderr Optional for py3 to match py2

Hm. It was intentional that we did not do this, I think. I expect it to break a lot of our code.

JasonGilholme

comment created time in 13 days

push eventpython/mypy

Jukka Lehtosalo

commit sha bb5649ec5df2b9c848253433ed3333a5a2dc7f14

Sync typeshed (#8343)

view details

push time in 20 days

PR merged python/mypy

Sync typeshed
+1 -1

0 comment

1 changed file

JukkaL

pr closed time in 20 days

push eventgvanrossum/pyxl3

Michael J. Sullivan

commit sha e6588c12caee49c43faf6aa260f04d7e971f6aa8

Bump the version number to 1.4

view details

push time in 20 days

push eventmsullivan/pyxl3

Michael J. Sullivan

commit sha 23f3c5851bda979f153dc3342a843d9d6417df42

Reduce startup overhead of pyxl being installed (#4) pyxl needs to register itself as a codec on python startup, but it doesn't need to actually import any of the pyxl machinery until it needs to decode something. The mild gymnastics performed (changing the module to import on startup to `fast_register` and then importing that from the original `register`) are to keep the diff size small while not breaking `register`'s functionality as a script. This shaves about 60ms off `python3 -c ''` with pyxl installed on my laptop (from 100ms to 40ms!), which is 10ms more than a slightly simpler change that just moves the `pyxl.codec.tokenizer` import into `pyxl_transform`.

view details

Michael J. Sullivan

commit sha 7d779f0bcb29aae4ba59ae4387b879793df5e319

Improve the generated code for <if> conditions (#5) Currently pyxl uses a global stack (!) of results from if conditions to determine whether to execute else branches. Instead, use if-else to do it in a more natural manner. Unfortunately, because the parser is structured in a very streaming manner, we don't know whether an if has an else block until after fully processing it, so we do some tasteless rewriting of the output to handle this. The main purpose of this is to produce better looking code so that we can compile everything to the target python and throw away the pyxl codec, but I suppose it also fixes a thread-safety bug and probably makes things faster too.

view details

Michael J. Sullivan

commit sha 96e9fc6390cbafa4a80732ac48eb2b39efe9f8fb

Eliminate the double call when there are children but no attributes (#6)

view details

Michael J. Sullivan

commit sha 2f05de635653735c23b34116fdb5e52caeceeeb1

Make all the tests pass in python 3 (#7) The code that is generated can still emit `unicode`, which I'm working around instead of fixing.

view details

Michael J. Sullivan

commit sha 8f3f4340273e028bea96f7f18589abf2101a9d51

Fix conditions when a ternary appears in them (#9)

view details

Michael J. Sullivan

commit sha 288713bc69a087dd5c5401ef9b195c13a622a2b0

Don't use rawhtml except when we need to avoid escaping (#8)

view details

Michael J. Sullivan

commit sha 9bea42544c7c9fe2ce9ea90a9a0fc0240be208c7

Avoid inserting an html.x_frag in many if/else blocks (#10) html.x_frag is needed in this case when there are multiple children, so we can track the number of children and avoiding inserting the x_frag.

view details

Michael J. Sullivan

commit sha f1268b7d0aaec561dc9b5b9a288200783bb11e2e

Revert "Eliminate the double call when there are children but no attributes" (#11) We decided that this was too risky because of components that override `__init__`. This reverts commit 96e9fc6390cbafa4a80732ac48eb2b39efe9f8fb.

view details

Michael J. Sullivan

commit sha 5a79ae5dab87edb0b35157b0dc3c49a76fd67aa3

Add an invertible codec variant (#12) The normal pyxl codec is irritatingly incompatible with syntax-tree based code modification tools, since even if they read in their input using the pyxl codec, they lose it in the output. In order to allow using tools like pyannotate, modernize, and black, we add an invertible pyxl codec that produces python code that can be reversed back into pyxl. Basically, ignoring many details, we turn ``` <foo> <bar baz="{baz}" spam="{spam}" eggs="{eggs}" /> </foo> ``` into ``` html.PYXL('''<foo> <bar baz="{{{}}}" spam="{{{}}}" eggs="{{{}}}" /> </foo>''', baz , spam , eggs ) ``` from which we can reconstruct the original, even if the arguments get modified. Additionally, we actually store more information to support reindenting the html if its start column changes due to black or some similar tool, and the actual generated pyxl code is also in there to allow using tools that remove unused imports. Some substantial refactors are unfortunately lumped in here. This adds tests that every file in the tests directory * Round-trips via the new pyxl codec without any changes * Produces the same AST after being formatted with black * Is idempotent when formatting with black I also ran these tests against all of the pyxl code we have internally. There is one bug revealed by this that is not fixed, which is that we will spuriously insert extra space into multi-line string literals in a python fragment. We only do that a single digit number of times so I'm going to call it good enough.

view details

Michael J. Sullivan

commit sha f0c7629efd53e71c425fc7026e981e1618cf6ada

Bump the version number (#13)

view details

Michael J. Sullivan

commit sha a6cdfabb554756bf3a31a44ad80e053a4944be3c

Emit 'str' instead of 'unicode' when joining together attr values (#14) To the extent we care about this code actually working in Python 3, this is obviously an improvement. We don't /really/ care about that, so this is really more about making the typechecking work in both 2 and 3. (Using `str` on 2 is incorrect from an actual running code perspective but should basically be fine from a mypy typechecking perspective. We could use `typing.Text` or `six.string_types` but that adds a dependency and would require an import in files that use it.)

view details

Michael J. Sullivan

commit sha e573311f867f71082922aae7397093156746614a

Bump the version number to 1.2 (#15)

view details

Michael J. Sullivan

commit sha 80e58c6b8ac6d931532bf70e5673a49278b92fec

Update MANIFEST

view details

Michael J. Sullivan

commit sha 3cfddef60b78c6352209102833a4a891bc9af9cc

Parenthesize generator expressions (#16) This fixes issues with commas after a generator expression as a sole argument being disallowed in Python 3.7 but allowed in earlier versions. We only parenthesize generator expressions since we're trying to keep the output looking good so it can be used to remove pyxl if needed...

view details

Michael J. Sullivan

commit sha c0c6c96dd05ae25aca35fdeb8fec3003bcdc2d40

Include trailing comments in the literally quoted pyxl block (#17) This keeps the black+pyxl combo from shifting type: ignores off the line.

view details

Michael J. Sullivan

commit sha 2860935ecbd5b2260bc75e6f539d8fb8cee7e096

Bump the version number to 1.3 (#18)

view details

Michael J. Sullivan

commit sha 0b23f20a02ec441f6a969626e9152a8a8093dd24

Allow overriding what function we use to convert to str (#19) Always calling `str` causes trouble in the case where we are using the codec to depyxlize python 2 code.

view details

Michael J. Sullivan

commit sha e6588c12caee49c43faf6aa260f04d7e971f6aa8

Bump the version number to 1.4

view details

push time in 20 days

delete branch msullivan/pyxl3

delete branch : str-function-config

delete time in 20 days

push eventgvanrossum/pyxl3

Michael J. Sullivan

commit sha 0b23f20a02ec441f6a969626e9152a8a8093dd24

Allow overriding what function we use to convert to str (#19) Always calling `str` causes trouble in the case where we are using the codec to depyxlize python 2 code.

view details

push time in 20 days

PR merged gvanrossum/pyxl3

Allow overriding what function we use to convert to str

Always calling str causes trouble in the case where we are using the codec to depyxlize python 2 code.

+14 -13

0 comment

3 changed files

msullivan

pr closed time in 20 days

PR opened gvanrossum/pyxl3

Allow overriding what function we use to convert to str

Always calling str causes trouble in the case where we are using the codec to depyxlize python 2 code.

+14 -13

0 comment

3 changed files

pr created time in 20 days

create barnchmsullivan/pyxl3

branch : str-function-config

created branch time in 20 days

issue closedpython/mypy

Dynamic base classes

Currently mypy isn't happy about dynamic base classes, even though these are not uncommon. Maybe mypy could do a better job.

Currently this works:

base: Any = create_class()

class A(base): ...

However, these don't work:

base2 = create_class()  # no annotation for base2 -> doesn't work
class B(base2): ...

class C(create_class()): ...  # function call as base class

base3: Type[A] = ...
class D(base3): ...

A plugin architecture (https://github.com/python/mypy/issues/1240) would help with commonly used libraries, but it wouldn't help with more ad-hoc uses of dynamic base classes.

closed time in 20 days

JukkaL

issue commentpython/mypy

Dynamic base classes

We've got a plugin system that supports this now and I doubt we'll do better

JukkaL

comment created time in 20 days

issue closedpython/mypy

mypy requires an annotation for empty `frozenset`

Related to #1164:

x = frozenset()
t.py:1: error: Need type annotation for 'x'

I'll note that a similar case for empty tuple does not require an annotation. I think this is different from x = set() because frozenset is immutable.

closed time in 21 days

asottile

issue closedpython/mypy

Dict values not inferred correctly

In this code:

from typing import Dict, Optional


def f (x: Optional[int]):
    if x is not None:
        x += 1

mypy is smart enough to understand to infer that x is of type int in the last line. However is this example:

from typing import Dict, Optional

d = {"k": 1}  # type: Dict[str, Optional[int]]

if d.get("k") is not None:
    d["k"] += 1

mypy is not able to infer that d["k"] is an int. We've been using mypy for the few months and this is really painful, since it's a very common programming pattern.

closed time in 21 days

mehdigmira

issue commentpython/mypy

Dict values not inferred correctly

I don't think we're going to support this

mehdigmira

comment created time in 21 days

issue closedpython/mypy

No config file option corresponding to --strict

strict = True in the config should enable the strict mode, but it doesn't work.

closed time in 21 days

JukkaL

issue commentpython/mypy

No config file option corresponding to --strict

This got fixed I believe

JukkaL

comment created time in 21 days

issue closedpython/mypy

Disable specific checks

Hello!

I've tried to run mypy on my project and I've got, among others, lots of 'Need type annotation for variable' errors. Since I'm not quiet ready to annotate all of those, I'd like to disable this kind of errors. Any way to do it? If no, let this issue be a feature request.

closed time in 21 days

AmatanHead

issue commentpython/mypy

Disable specific checks

Well we have done the error codes thing sort of. Closing in favor of #7599.

AmatanHead

comment created time in 21 days

issue closedpython/mypy

Infer more specific type after equality or membership check

from typing import Union

def foo(bar: Union[str, int]):
	if bar in ["a", "b", "c"]:
                # to a human, bar is clearly a str. mypy still thinks it's a Union[str, int]
		return bar.upper()
	else:
		return bar
$ mypy test.py 
test.py:5: error: Item "int" of "Union[str, int]" has no attribute "upper"

The same thing happens if the condition is, for example, bar == "a".

  • Are you reporting a bug, or opening a feature request?

Feature request

  • What is the behavior/output you expect?

Mypy to understand the effect of conditions like bar == "a" or bar in ["a"], like it already does with isinstance checks

closed time in 21 days

jackriccomini

issue commentpython/mypy

Infer more specific type after equality or membership check

I think we're probably not going to do this

jackriccomini

comment created time in 21 days

issue closedpython/mypy

Idea: use inferred types for documentation

It would be really cool to "see" the types that mypy infers.

There's a project to use type hints for generated documentation: https://github.com/agronholm/sphinx-autodoc-typehints

Perhaps something like this could be done with types inferred by mypy instead of explicit type hints?

closed time in 21 days

dimaqq

issue commentpython/mypy

Idea: use inferred types for documentation

I don't think we're going to have this as a built-in mypy feature, though it could be done by an external project calling into mypy

dimaqq

comment created time in 21 days

issue closedpython/mypy

Add support for outputting warnings messages to log file

I want to easily parse warnings with Jenkins's Warnings Next Generation Plugin. It's super helpful for keeping my projects clean.

Right now, I have to do something like this on Windows to get a file which the Warnings parser can use.

mypy -p pykdu_compress > ${WORKSPACE}\\logs\\mypy.log

This works most of the time. However, I cannot use tee when testing on Windows machines. For this reason, if I want see the warnings data produced, I either have archive the log file and open it again or add another step that prints the contents of the file to the console. Anyways, it seems like there should be an easier way.

flake8 does some to accommodate this.

flake8 pykdu_compress --tee --output-file=${WORKSPACE}\\logs\\flake8.log"

This makes it possible but I think it could be simpler in mypy. For example:

mypy -p pykdu_compress --warning-messages  ${WORKSPACE}\\logs\\mypy.log

closed time in 21 days

henryborchers

issue commentpython/mypy

Add support for outputting warnings messages to log file

This falls into a category of "I guess I would probably review a PR for it" but I also think it doesn't really make sense.

henryborchers

comment created time in 21 days

issue closedpython/mypy

mypy is not looking inside Python's any()

(mypy-0.641, Python 3.6.7)

from typing import Optional

def test_1(inp1: Optional[int] = None, inp2: Optional[int] = None) -> None:
    if any(attribute is None for attribute in (inp1, inp2)):
        pass
    else:
        if inp1 <= 0:
            print('<=0')

I am expecting type checking for the above function to work the same as for the one below:

def test_2(inp1: Optional[int] = None, inp2: Optional[int] = None) -> None:
    if inp1 is None or inp2 is None:
        pass
    else:
        if inp1 <= 0:
            print('<=0')

i.e. in the else block, the None case should be excluded and inp1 type should be inferred as int. Instead, mypy says (only for test_1()):

mypytest.py:7: error: Unsupported operand types for >= ("int" and "None")
mypytest.py:7: note: Left operand is of type "Optional[int]"

Is this something which should be easily fixed, or am I overlooking some edge cases?

closed time in 21 days

alkamid

issue closedpython/mypy

Support invoking mypy from setuptools (feature request)

It would be great if mypy (or some external tool, mypy-setuptools or something) could provide an easy way to run mypy against just the files in a distribution.

There was some work done on this in #994 (to close #992) by @rowillia, but it was reverted without comment in 964a17587231c6f09ba24f6dd19648586ea3d655 by @JukkaL.

Given the python-3.6+ dependence of mypy, and the fact it can check older python versions, I think it would make sense for this setuptools plugin to ultimately just invoke subprocess.check_call(['mypy', ...]), which would allow it to be used on python2 projects too. For this reason, it would make sense for it not to live in the mypy repo, as it would need to be installable within python instances where mypy is not.

One difficulty here is how exactly to test only the files in a distribution. Some options are:

  • Running against the source - this doesn't respect the package_dir argument in setuptools.
  • Collecting distribution.modules and distribution.packages - this will end up checking the full contents of any namespace package partially provided by this distribution
  • Inspecting an egg or wheel somehow, and letting mypy take one of these as an argument?

closed time in 21 days

eric-wieser

issue commentpython/mypy

Support invoking mypy from setuptools (feature request)

I think this would need to be an external tool

eric-wieser

comment created time in 21 days

issue closedpython/mypy

Difference Types

Feature request:

from typing import Mapping, Iterable

A = Difference[Union[Mapping, Iterable], str]

Difference to create a new type that validates the value conforms to the first provided type and doesn't conform to the other type.

closed time in 21 days

iddan

issue commentpython/mypy

Difference Types

This could be good but it is niche and would probably affect everything in the type system

iddan

comment created time in 21 days

issue closedpython/mypy

Conditional redefinition of builtin doesn't work

Mypy complains about the type of next in the following example where we define a builtin if it doesn't exist:

try:
    next   # Error: Cannot determine type of next
except NameError:
    next = lambda x: x.next()

Mypy could fall back to the builtins module namespace during semantic analysis if it can't determine the type of a module-level name. This way the name would refer to the built-in definition until the first redefinition in the file.

(This is derived from #649, originally reported by @rbtcollins).

closed time in 21 days

JukkaL

issue closedpython/mypy

Support type(None) as a type

type(None) should be equivalent to None, as per PEP 484 draft.

closed time in 21 days

JukkaL

issue commentpython/mypy

Support type(None) as a type

I don't think anyone cares

JukkaL

comment created time in 21 days

issue closedpython/mypy

Coverage issue when using getattr

I recently began adding type annotations to a project and I'm running into an issue where I can seem to get coverage on a statement which is using getattr. In my actual code, getattr() is being called on a library loaded with ctypes.cdll.LoadLibrary(), but I was able to reproduce the problem with a much simpler example that just uses a simple class. Here's the example:

class Foo:
    a = 1

a = getattr(Foo(), 'a') # type: int

I also tried this with the newer Python 3.6 syntax of:

a: int = getattr(Foo(), 'a')

Both versions produced the same result, which was that the assignment of 'a' showed up in red (not covered) in the mypy coverage report.

I can understand why getattr() would not be able to determine the type of its return value, but with the explicit type in the getattr assignment, I was expecting the coverage error to go away. Instead, the coverage report still shows this line as not covered, even though the type is tracked properly for later code in the module (and so those lines show up as being covered).

I'm seeing this with mypy 0.560 on Python 3.6.4, with defaults to mypy flags. The only option I'm giving it is '--html-report' to generate the coverage report.

I haven't tried testing this against mypy from Git master yet. I thought I'd start here to see if I'm simply misunderstanding how this should be done. Any suggestions for how to get code like this show up as covered would be greatly appreciated!

closed time in 21 days

ronf

issue commentpython/mypy

Coverage issue when using getattr

Yeah probably we aren't doing much work on the coverage report details

ronf

comment created time in 21 days

issue closedpython/mypy

Recognize dynamic creation of named tuples.

This appeared in https://github.com/python/typing/issues/427

We can support something like this:

base_fields = [('x', int), ('y', int)]
label = [('label', str)]
LabeledPoint3D = NamedTuple('LabeledPoint3D', base_fields + [('z', int)] + label)

closed time in 21 days

ilevkivskyi

issue commentpython/mypy

Recognize dynamic creation of named tuples.

I don't think we'll do this

ilevkivskyi

comment created time in 21 days

issue closedpython/mypy

Use `any` and `all` to make collection non-optional

I have seen patterns like this several times:

def func() -> Optional[int]:
    pass

def test() -> List[int]:
    vals: Iterable[Optional[int]] = [func() for _ in some_list]
    if all(vals):
        return list(vals)  # None can't be in 'vals' here.
    return []

It would be convenient if binder could understand this for covariant collections.

closed time in 21 days

ilevkivskyi

issue commentpython/mypy

Use `any` and `all` to make collection non-optional

I think if we only do this for covariant containers then it feels pretty niche and if we do it for invariant containers then it has problems, so I'm going to close this, but if somebody disagrees with me feel free to reopen

ilevkivskyi

comment created time in 21 days

issue closedpython/mypy

Optional strict checking of isinstance checks

The current semantics of isinstance checks make some assumptions about inheritance, such as there being no multiple inheritance from certain classes. This is probably reasonable as a default, since it makes easier to annotate legacy codebases. However, we could provide an option to have safer and stricter checking of isinstance checks. The exact behavior of this mode is still not quite clear.

See discussion in #3605 for further context.

closed time in 21 days

JukkaL

issue commentpython/mypy

Optional strict checking of isinstance checks

I don't think this meets the bar of adding a new flag and we're moving towards more intersection stuff

JukkaL

comment created time in 21 days

issue closedpython/mypy

generic methods/generic self don't seem to play with parameterized generics

(There are a couple of other issues that I think might be the same thing as this question, but I'm not sure, because they're posed at a lower level—apologies if this is actually a duplicate. #3153, maybe?)

The generic methods and generic self docs show how write a class with methods that accept/return arguments of the most precise type, so things like this work as intended:

from typing import Generic, TypeVar

T = TypeVar('T', bound='Modular')


### this works! yay!
class Modular(object):
    modulus = 0  # type: int

    def __init__(self, i):
        # type: (int) -> None
        self.i = i % self.modulus

    def __add__(self, other):
        # type: (T, T) -> T
        return self.__class__((self.i + other.i) % self.modulus)


class Mod5(Modular):
    modulus = 5


class Mod6(Modular):
    modulus = 6


Mod5(3) + Mod6(3)  # statically "disallowed"

mypy won't let me add Mod5s to Mod6s, hooray. But what if the relevant class is itself generic? This doesn't work:

In = TypeVar('In', contravariant=True)
Out = TypeVar('Out', covariant=True)
A = TypeVar('A')
B = TypeVar('B')

F = TypeVar('F', bound='FunctionLike') 

class FunctionLike(Generic[In, Out]):
    def call(self, arg):
        # type: (In) -> Out
        raise NotImplementedError

    def compose(self, other):
        # type: (F[In, Out], F[Out, B]) -> F[In, B]  # can't index `F`, so this doesn't work
        raise NotImplementedError

The type of compose shouldn't be (FunctionLike[In, Out], FunctionLike[Out, B]) -> FunctionLike[In, B], because then any two instances of any two subclasses could be composed together. It can't be (F, F) -> F because then all the type parameters are the same.

Is there a way to express this?

closed time in 21 days

bwo

issue commentpython/mypy

generic methods/generic self don't seem to play with parameterized generics

Closing this in favor of the other issues linked

bwo

comment created time in 21 days

issue closedpython/mypy

Allow subclassing Callable

This is not a priority, but probably we could allow subclassing Callable, some people might find this "nicer", than defining a __call__ method (e.g. if this is an ABC or a protocol). For example this already works at runtime:

class C(Callable[[int], int]):
    attr: str

This would be implemented by returning CallableType for C with a fallback to an instance of the original TypeInfo (like for tulpes, see also #3831).

closed time in 21 days

ilevkivskyi
more