Commit Graph

25 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
49173e472f
Minor follow-on to PR #1334 (Fix enum value's __int__ returning non-int when underlying type is bool or of char type) (#3232)
* Minor tweaks.

* Restoring tests/pybind11_tests.h version from master, removing just the comment and empty line that was added in PR #3087; those were made obsolete by the pragma cleanup that concluded with PR #3186.

* More-to-the-point test for Python 3.
2021-08-31 08:52:04 -07:00
Ye Zhihao
cb60ed49e4
Fix enum value's __int__ returning non-int when underlying type is bool or of char type (#1334)
* Use equivalent_integer for enum's Scalar decision

* Add test for char underlying enum

* Support translating bool type in enum's Scalar

* Add test for bool underlying enum

* Fix comment in test

* Switch from `PYBIND11_CPP20` macro to `PYBIND11_HAS_U8STRING`

* Refine tests

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2021-08-26 14:34:24 -07:00
Aaron Gokaslan
9df2f1ff13
maint(precommit): Apply isort (#3195)
* Apply isort

* Tweak isort config

* Add env.py as a known_first_party

* Add one missing known first party

* Make config compat with older isort versions

* Add another comment

* Revert pyproject setting
2021-08-13 12:37:05 -04:00
Eric Cousineau
2110d2d8ba
enum: add missing Enum.value property (#2739)
* enum: Add Enum.value property

* simplify

* address review
2020-12-31 11:08:15 -05:00
Ralf W. Grosse-Kunstleve
cecdfadc58
minor cleanup: fixing or silencing flake8 errors (#2731)
* minor cleanup: fixing or silencing flake8 errors

* ci: lock CMake to non-Universal version

* Update .github/workflows/ci.yml

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2020-12-18 19:41:43 -05:00
Yannick Jadoul
c58758d049
fix: add reasonable argument names to enum_ methods (#2637)
* Add argument names to enum_ methods

* Add test_enum::test_docstring_signatures
2020-11-10 12:49:42 -05:00
Henry Schreiner
c50f90eca6
style: use Black everywhere (#2594)
* style: use Black everywhere

* style: minor touchup from review
2020-10-16 16:38:13 -04:00
David Vo
5e6ec49652
Add enum value to enum repr (#2126)
This changes enum reprs to look like `<Enum.name: value>` similarly to
the Python enum module.

This keeps the str of enums as `Enum.name`, like the Python enum module.
2020-09-20 01:12:19 +02:00
Henry Schreiner
d8c7ee00a6
ci: GHA basic format & pre-commit (#2309) 2020-07-20 13:35:21 -04:00
Wenzel Jakob
31680e6f9c Implicit conversion from enum to int for Python 3.8 (fix by @sizmailov) 2019-09-20 11:06:10 +02:00
Wenzel Jakob
21d0eb460f Fix Python 3.8 test regression 2019-09-20 09:38:30 +02:00
Sergei Izmailov
09f0829401 Avoid conversion to int_ rhs argument of enum eq/ne (#1912)
* fix: Avoid conversion to `int_` rhs argument of enum eq/ne

* test: compare unscoped enum with strings

* suppress comparison to None warning

* test unscoped enum arithmetic and comparision with unsupported type
2019-09-19 18:23:27 +02:00
Lori A. Burns
f6c4c1047a restores __invert__ to arithmetic-enabled enum, fixes #1907 (#1909) 2019-09-04 22:16:21 +02:00
Tarcísio Fischer
54eb8193e5 Fix scoped enums comparison for equal/not equal cases (#1339) (#1571) 2018-10-24 11:18:58 +02:00
Wenzel Jakob
f4245181ae enum_: move most functionality to a non-template implementation
This commit addresses an inefficiency in how enums are created in
pybind11. Most of the enum_<> implementation is completely generic --
however, being a template class, it ended up instantiating vast amounts
of essentially identical code in larger projects with many enums.

This commit introduces a generic non-templated helper class that is
compatible with any kind of enumeration. enum_ then becomes a thin
wrapper around this new class.

The new enum_<> API is designed to be 100% compatible with the old one.
2018-09-11 22:08:26 +02:00
Krzysztof Fornalczyk
5c8746ff13 check for already existing enum value added; added test (#1453)
* check for already existing enum value added; added test

* added enum value name to exception message

* test for defining enum with multiple identical names moved to test_enum.cpp/py
2018-09-11 10:59:56 +02:00
Boris Staletic
289e5d9cc2 Implement an enum_ property "name"
The property returns the enum_ value as a string.
For example:

>>> import module
>>> module.enum.VALUE
enum.VALUE
>>> str(module.enum.VALUE)
'enum.VALUE'
>>> module.enum.VALUE.name
'VALUE'

This is actually the equivalent of Boost.Python "name" property.
2018-04-07 19:11:35 -03:00
Wenzel Jakob
6d19036cb2
support docstrings in enum::value() (#1160) 2017-11-16 22:24:36 +01:00
Jason Rhinelander
391c75447d Update all remaining tests to new test styles
This udpates all the remaining tests to the new test suite code and
comment styles started in #898.  For the most part, the test coverage
here is unchanged, with a few minor exceptions as noted below.

- test_constants_and_functions: this adds more overload tests with
  overloads with different number of arguments for more comprehensive
  overload_cast testing.  The test style conversion broke the overload
  tests under MSVC 2015, prompting the additional tests while looking
  for a workaround.

- test_eigen: this dropped the unused functions `get_cm_corners` and
  `get_cm_corners_const`--these same tests were duplicates of the same
  things provided (and used) via ReturnTester methods.

- test_opaque_types: this test had a hidden dependence on ExampleMandA
  which is now fixed by using the global UserType which suffices for the
  relevant test.

- test_methods_and_attributes: this required some additions to UserType
  to make it usable as a replacement for the test's previous SimpleType:
  UserType gained a value mutator, and the `value` property is not
  mutable (it was previously readonly).  Some overload tests were also
  added to better test overload_cast (as described above).

- test_numpy_array: removed the untemplated mutate_data/mutate_data_t:
  the templated versions with an empty parameter pack expand to the same
  thing.

- test_stl: this was already mostly in the new style; this just tweaks
  things a bit, localizing a class, and adding some missing
  `// test_whatever` comments.

- test_virtual_functions: like `test_stl`, this was mostly in the new
  test style already, but needed some `// test_whatever` comments.
  This commit also moves the inherited virtual example code to the end
  of the file, after the main set of tests (since it is less important
  than the other tests, and rather length); it also got renamed to
  `test_inherited_virtuals` (from `test_inheriting_repeat`) because it
  tests both inherited virtual approaches, not just the repeat approach.
2017-08-05 18:46:22 -04:00
Wenzel Jakob
7653a115bd pytest target: add USE_TERMINAL flag
The added flag enables non-buffered console output when using Ninja
2017-04-29 16:35:28 +02:00
Wenzel Jakob
e6fd2cd5ab enum_: fix implicit conversion on Python 2.7
Enumerations on Python 2.7 were not always implicitly converted to
integers (depending on the target size). This patch adds a __long__
conversion function (only enabled on 2.7) which fixes this issue.

The attached test case fails without this patch.
2017-04-29 16:35:28 +02:00
Matthieu Bec
af936e1987 Expose enum_ entries as "__members__" read-only property. Getters get a copy. 2017-03-03 08:45:50 -08:00
Dean Moldovan
bad1740213 Add checks to maintain a consistent Python code style and prevent bugs (#515)
A flake8 configuration is included in setup.cfg and the checks are
executed automatically on Travis:

* Ensures a consistent PEP8 code style
* Does basic linting to prevent possible bugs
2016-11-20 21:21:54 +01:00
Pim Schellart
90d27805b9 Extended enum support (#503)
* Allow enums to be ordered
* Support binary operators
2016-11-16 17:28:11 +01:00
Dean Moldovan
a9a37b4e31 Move enum tests into a new file
There are more enum tests than 'constants and functions'.
2016-08-19 13:19:38 +02:00