Skip to content

Conversation

@orenmn
Copy link
Contributor

@orenmn orenmn commented Sep 16, 2017

  • in stgdict.c: replace the assertion with a test whether the type of the attribute is PyCField_Type, i.e. whether the attribute was specified in _fields_.
  • in test_anon.py: add a test to verify that the assertion failure is no more, and that AttributeError is raised instead.

https://bugs.python.org/issue31490

assert(Py_TYPE(descr) == &PyCField_Type);
if (Py_TYPE(descr) != &PyCField_Type) {
PyErr_Format(PyExc_AttributeError,
"'%U' is specified in _anonymous_ but not in "
Copy link
Member

Choose a reason for hiding this comment

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

What if fname is not a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, PyObject_GetAttr() would return NULL

# AttributeError: 'x' is specified in _anonymous_ but not in _fields_
with self.assertRaises(AttributeError):
class Name(Structure):
_fields_ = []
Copy link
Member

Choose a reason for hiding this comment

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

From the documentation:

_anonymous_ must be already defined when _fields_ is assigned, otherwise it will have no effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all right. should we change the other tests too?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, if they are wrong, it should be a separate issue. OK, left the code as is.

# AttributeError: 'x' is specified in _anonymous_ but not in _fields_
with self.assertRaises(AttributeError):
class Name(Structure):
_fields_ = []
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, if they are wrong, it should be a separate issue. OK, left the code as is.

@serhiy-storchaka serhiy-storchaka added needs backport to 2.7 type-bug An unexpected behavior, bug, or error labels Sep 17, 2017
@serhiy-storchaka serhiy-storchaka merged commit 30b61b5 into python:master Sep 17, 2017
@miss-islington
Copy link
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6.
🐍🍒⛏🤖

1 similar comment
@miss-islington
Copy link
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @orenmn and @serhiy-storchaka, I had trouble checking out the 2.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 30b61b51e05d2d43e8e2e783b0a9df738535423b 2.7

1 similar comment
@miss-islington
Copy link
Contributor

Sorry @orenmn and @serhiy-storchaka, I had trouble checking out the 2.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 30b61b51e05d2d43e8e2e783b0a9df738535423b 2.7

@miss-islington
Copy link
Contributor

Sorry @orenmn and @serhiy-storchaka, I had trouble checking out the 3.6 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 30b61b51e05d2d43e8e2e783b0a9df738535423b 3.6

@bedevere-bot
Copy link

GH-3774 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 26, 2017
…mous_ attr is defined only outside _fields_. (pythonGH-3615)

(cherry picked from commit 30b61b5)
serhiy-storchaka pushed a commit that referenced this pull request Sep 27, 2017
…mous_ attr is defined only outside _fields_. (GH-3615) (#3774)

(cherry picked from commit 30b61b5)
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Sep 27, 2017
…mous_ attr is defined only outside _fields_. (pythonGH-3615)

(cherry picked from commit 30b61b5)
@miss-islington
Copy link
Contributor

Thanks @orenmn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 27, 2017
…mous_ attr is defined only outside _fields_. (pythonGH-3615)

(cherry picked from commit 30b61b5)
@bedevere-bot
Copy link

GH-3780 is a backport of this pull request to the 2.7 branch.

serhiy-storchaka pushed a commit that referenced this pull request Sep 27, 2017
…mous_ attr is defined only outside _fields_. (GH-3615) (#3780)

(cherry picked from commit 30b61b5)
serhiy-storchaka pushed a commit that referenced this pull request Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants