← 输入框|github.com|刷新
Skip to content

Immutable VersionInfo - #97

Merged
s-celles merged 1 commit into
python-semver:masterfrom
s-celles:immutable
May 31, 2018
Merged

s-celles merged 1 commit into
python-semver:masterfrom
s-celles:immutable

Conversation

@s-celles

Copy link
Copy Markdown
Member

Closes #96

@s-celles

Copy link
Copy Markdown
Member Author

I don't understand why CI is broken with pypy and Python 2.7.

Any idea?

@s-celles

Copy link
Copy Markdown
Member Author

CI fixed for Python 2.7 and PyPi
PR is ready to be merged in the next coming days.

Comment thread semver.py Outdated
def build(self):
return self._build

def __setattr__(self, name, value):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this function is unnecessary

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought also that setattr wasn't necessary...
but not with Python 2.7 and Pypy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we want to have private attributes be mutable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You are right ...
This build shows that __setattr__ is not required.

Although what is required for Python 2.7 and Pypi is inheriting VersionInfo from object.

Comment thread test_semver.py
assert str(v) == s_version


def test_immutable():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also add a test to check if it's possible to add new attribute? Something like this:

try:
    v.some_attribute = 1
except:
    ...

Comment thread semver.py Outdated
def build(self):
return self._build

def __setattr__(self, name, value):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we want to have private attributes be mutable?

Comment thread semver.py Outdated

def __setattr__(self, name, value):
if name not in self.__slots__:
raise AttributeError

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even if so, it's better to pass name to AttributeError to avoid any confusions.

@s-celles

Copy link
Copy Markdown
Member Author

Thanks @ppkt and @kxepal
Can I merge now?

@kxepal kxepal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGFM 👍

@ppkt ppkt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Of course, thanks :)

@s-celles
s-celles merged commit 97d41b9 into python-semver:master May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants