tefra / xsdata

Naive XML & JSON Bindings for python
https://xsdata.readthedocs.io
MIT License
324 stars 59 forks source link

Check type hinting, extra parentheses for attribute. #1000

Closed skinkie closed 6 months ago

skinkie commented 6 months ago

Using Pycharm the following type hinting is generated for the TimetableFrame class. These specific classes have been generated by the main version of xsdata, using the NeTEx next branch.

types

    journey_interchanges: Optional[JourneyInterchangesInFrameRelStructure] = (
        field(
            default=None,
            metadata={
                "name": "journeyInterchanges",
                "type": "Element",
                "namespace": "http://www.netex.org.uk/netex",
            },
        )
    )

I think the 'field ( ... )' is undesirable. It looks like that comes from the extra parentheses.

tefra commented 6 months ago

@skinkie edit the ticket and add some proper description please.

tefra commented 6 months ago

The extra parenthesis, is ruff's attempt to keep the maximum line length, it doesn't affect the dataclass in any way, increase the max line length if you don't like it

tefra commented 6 months ago

At some point, I plan to surface the ruff config somehow and people can pick and choose, format/lint options but for now, only the max line length can be changed

skinkie commented 6 months ago

The extra parenthesis, is ruff's attempt to keep the maximum line length, it doesn't affect the dataclass in any way, increase the max line length if you don't like it

So you would say that the type hinting in PyCharm has a bug?

tefra commented 6 months ago

I think so, all tests in the samples and w3c-tests repos pass

skinkie commented 6 months ago

Reported upstream. I think I'll then for now explicitly increase the max line length to 320.

https://youtrack.jetbrains.com/issue/PY-71614/PyCharm-type-hints-for-dataclasses-fail-when-field-is-enclosed-with-parentheses