Commit Graph

41 Commits

Author SHA1 Message Date
Kodi Arfer 80eb27906a Update copyright years 2020-01-09 14:05:12 -05:00
Kodi Arfer 7ba1407257 Remove hy._compat.PY3 2019-06-04 14:01:59 -04:00
Kodi Arfer 5dcb03b64d Move `isidentifier` to hy.lex 2019-06-04 14:01:59 -04:00
Kodi Arfer d7da03be12 Simplify hy._compat.isidentifier 2019-06-04 14:01:59 -04:00
Kodi Arfer e45cee575a Move `rename_function` to hy.macros 2019-06-04 14:01:59 -04:00
Kodi Arfer 7991c59480 Remove handling of UCS-2 2019-06-04 14:01:59 -04:00
Kodi Arfer c255f0d03c Remove old hy._compat raising code 2019-06-04 14:01:59 -04:00
Kodi Arfer ecf0352d37 Remove aliases: `builtins`, `FileNotFoundError` 2019-06-04 14:01:59 -04:00
Kodi Arfer bba97ab2a6 Remove hy._compat's type aliases 2019-06-04 14:01:59 -04:00
Kodi Arfer 8df0a41d7d Provide Module(..., type_ignores) for Python 3.8 2019-04-23 15:35:12 -04:00
Kodi Arfer ad97042b6b Don't test Python 3.4 2019-03-17 18:36:53 -04:00
Brandon T. Willard 4ae4baac2a Cache command line source for exceptions
Source entered interactively can now be displayed in traceback output.  Also,
the REPL object is now available in its namespace, so that, for instance,
display options--like `spy`--can be turned on and off interactively.

Closes hylang/hy#1397.
2019-02-07 13:45:41 -05:00
Brandon T. Willard fb6feaf082 Improve correspondence with Python errors and console behavior
Compiler and command-line error messages now reflect their Python counterparts.
E.g. where Python emits a `SyntaxError`, so does Hy; same for `TypeError`s.
Multiple tests have been added that check the format and type of raised
exceptions over varying command-line invocations (e.g. interactive and not).

A new exception type for `require` errors was added so that they can be treated
like normal run-time errors and not compiler errors.

The Hy REPL has been further refactored to better match the class-structured
API.  Now, different error types are handled separately and leverage more base
class-provided functionality.

Closes hylang/hy#1486.
2019-02-07 13:45:41 -05:00
Brandon T. Willard 51c7efe6e8 Retain compiled source and file information for exceptions
This commit refactors the exception/error classes and their handling.
It also retains Hy source strings and their originating file information, when
available, all throughout the core parser and compiler functions.

As well, with these changes, calling code is no longer responsible for providing
source and file details to exceptions,

Closes hylang/hy#657.
2019-02-07 13:43:58 -05:00
Kodi Arfer 62638b44a3 Update copyright years 2019-02-07 08:57:35 -05:00
Kodi Arfer f1e693c96b Fix a Python 2 crash 2019-02-03 14:13:48 -05:00
Jakub Wilk 28504ba85d Catch IndentationError in isidentifier()
Fixes:

    >>> from hy._compat import isidentifier
    >>> isidentifier(u"  0\n 0")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "hy/_compat.py", line 47, in isidentifier
        tokens = list(T.generate_tokens(StringIO(x).readline))
      File "/usr/lib/python2.7/tokenize.py", line 374, in generate_tokens
        ("<tokenize>", lnum, pos, line))
      File "<tokenize>", line 2
        0
        ^
    IndentationError: unindent does not match any outer indentation level
2018-11-27 17:15:21 -05:00
Brandon T. Willard 87a5b117a1 Implement new importer using PEP-302 semantics
Python 3.x is patched in a way that integrates `.hy` source files into
Pythons default `importlib` machinery.  In Python 2.7, a PEP-302 "importer"
and "loader" is implemented according to the standard `import` logic (via
`pkgutil` and later pure-Python `imp` package code).

In both cases, the entry-point for the loaders is through `sys.path_hooks` only.
As well, the import semantics have been updated all throughout to utilize
`importlib` and follow aspects of PEP-420.  This, along with some light
patches, should allow for basic use of `runpy`, `py_compile` and `reload`.

In all cases, if a `.hy` file is shadowed by a `.py`, Hy will silently use
`.hy`.
2018-08-25 22:50:38 -05:00
Yigong Wang 5ae6875e88 Fix `mangle` for Pythons compiled with UCS-2 2018-03-30 07:23:32 -07:00
Kodi Arfer 4c5dea0756 Use io.StringIO instead of the StringIO module 2018-03-13 14:57:31 -04:00
Kodi Arfer d252bb0e94 Mangle names that coincide with Python keywords 2018-03-13 14:55:55 -04:00
Kodi Arfer 52edad28e2 Overhaul mangling rules 2018-03-13 14:55:53 -04:00
Simon Gomizelj a2c8f50b30 Implement changes to support PEP 552 2018-02-09 16:43:25 -05:00
Kodi Arfer 6de7ddfee5 Update copyright years 2018-01-01 10:38:33 -05:00
Simon Gomizelj 1e4ad3167b Introduce for/a* and for/a expressions 2017-12-30 19:02:15 -05:00
Kodi Arfer 0fc96306bc Drop support for Python 3.3 2017-08-26 13:36:51 -07:00
Kodi Arfer 2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer a27d737e1c Drop support for Pythons 3 older than 3.3 2017-04-24 14:22:13 -07:00
Kodi Arfer 5aaa7d92d8 Shorten hy._compat 2017-04-24 14:18:56 -07:00
Kodi Arfer ef3bad7e03 Drop support for Python 2.6 2017-04-24 14:18:56 -07:00
Kodi Arfer 45b7a4ac9d Add bytestring literals 2017-02-19 09:04:45 +02:00
Zack M. Davis 0dbf2126cf adds support for Python 3.5 infix matrix multiplication
Python 3.5 will have a new commercial-at infix operator with the magic
methods __matmul__, __rmatmul__, and __imatmul__, unused as yet in the
standard library, but intended to represent matrix multiplication in
numerical code; see PEP 465 (https://www.python.org/dev/peps/pep-0465/)
for details. This commit (developed against Python 3.5 alpha 3) brings
support for this operator to Hy when running under Python 3.5 (or,
hypothetically as yet, greater). For Hy under Python <= 3.4, attempting
to use `@` in function-call position currently results in a NameError;
this commit does not change that behavior.

This is intended to resolve #668.
2015-04-12 21:45:39 -07:00
Ilia Choly 7ef4d37169 Fix completion bugs
* freezing issue
* missing __name__
* reader & macro completion
* improve underscore to dash conversion
* python 3/2 string compatibility
2015-01-19 12:17:12 -05:00
Ryan Gonzalez a6d9a963b5 Fix flake8 errors 2014-11-01 16:07:39 -05:00
Ryan Gonzalez d01b6bbacc Fix Python 3 re-raising 2014-11-01 15:00:41 -05:00
Nicolas Dandrimont 8bfa4f33fc Add set comprehensions, dict comprehensions and generator expressions
Closes: #14 (woo, two-digit tickets)
2014-01-16 00:49:48 +01:00
Paul Tagliamonte de31aea5d2 Cleanup use of PY3* in the compiler. 2014-01-03 20:02:36 -05:00
Paul Tagliamonte 590d3bf1df Clean up compare to use the tuple. Thanks @olasd 2014-01-01 22:33:44 -05:00
Berker Peksag 8120a25c08 Add py_compile.{MAGIC, wr_long} to hy._compat.
Closes #344.
2013-12-29 13:10:36 +02:00
Nicolas Dandrimont 295e1240ad PY3 should really check for Python >= 3 2013-09-29 14:53:44 +02:00
Berker Peksag f21ddeeded Add hy._compat module.
There was a couple of duplicate imports and type checkings in the
codebase. So I added a new module to unify all Python 2 and 3
compatibility codes.

Also, this is a somewhat common pattern in Python. See Jinja2 for
example:

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/_compat.py
2013-09-29 12:10:08 +03:00