rbarrois / python-semanticversion

Semantic version comparison for Python (see http://semver.org/)
BSD 2-Clause "Simplified" License
281 stars 74 forks source link

TypeError when trying to access Spec.specs #82

Closed iamdefinitelyahuman closed 5 years ago

iamdefinitelyahuman commented 5 years ago

Python version: 3.6.8 semantic_version version: 2.8.1 OS: Ubuntu 18.04

Possibly related to #79 - I'm getting a TypeError whenever I try to access Spec.specs with any of the following conditions:

The traceback is identical in every case:

>>> Spec('0.1.0').specs
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/computer/code/venv/lib/python3.6/site-packages/semantic_version/base.py", line 1161, in specs
    return list(self)
  File "/home/computer/code/venv/lib/python3.6/site-packages/semantic_version/base.py", line 1169, in __iter__
    for clause in self.clause:
TypeError: 'Range' object is not iterable

Without a patch version, or using a ^ operator (even with a patch version) I have no issues:

>>> Spec('0.1').specs
[<SpecItem: >= Version('0.1.0', partial=True)>, <SpecItem: < Version('0.1.1', partial=True)>]
>>> Spec('^0.1.0').specs
[<SpecItem: < Version('0.2.0', partial=True)>, <SpecItem: >= Version('0.1.0', partial=True)>]
rbarrois commented 5 years ago

Hi! This is indeed a regression related to the recent new features.

However, the .specs API is deprecated, and removal planned in the next major version; could you describe how you're using it? I didn't see it as actually useful, but it seems I was wrong ;)

iamdefinitelyahuman commented 5 years ago

I'm using it to standardize pragma statements within solidity smart contracts. Perhaps there's a cleaner or different way to do this and certainly I'll have to look for one before the major upgrade :)

Here is the code where I'm accessing .specs - https://github.com/iamdefinitelyahuman/brownie/blob/05e34c0c9e3b7595071ffaff2f0c19c81da58471/brownie/project/compiler.py#L183-L201

For now tho my build is failing everywhere as this is an integral component... do you think you can push a fix soon-ish or am I better off releasing another version of my package that requires ==2.6.0? (hope that doesn't sound demanding, very happy to deal with it on my end and grateful to you that this package exists)

Thanks :)

rbarrois commented 5 years ago

I'll give it my best.

Regarding your code, I strongly suggest taking a look at the new design with custom spec syntax parsers and subcomponents; it might be useful to directly parse your pragmas.

iamdefinitelyahuman commented 5 years ago

:pray: will do, thanks heaps

rbarrois commented 5 years ago

Fixed in version 2.8.2! :wink:

iamdefinitelyahuman commented 5 years ago

Thanks! I'm just finishing up tests on my own updated version to move away from .specs - the new NpmSpec class has allowed me to refactor out a bunch of code. Great stuff!