All Projects → aroberge → ideas

aroberge / ideas

Licence: other
Easy creation of custom import hooks to experiment on alternatives to Python's syntax; see https://aroberge.github.io/ideas/docs/html/

Programming Languages

python
139335 projects - #7 most used programming language
Batchfile
5799 projects

Projects that are alternatives of or similar to ideas

python-imphook
Simple and clear import hooks for Python - import anything as if it were a Python module
Stars: ✭ 23 (-61.02%)
Mutual labels:  importlib, import-hook, import-hooks
TemplePlus
ToEE hooks, extensions and fixes
Stars: ✭ 73 (+23.73%)
Mutual labels:  hook
Xhook
🔥 A PLT hook library for Android native ELF.
Stars: ✭ 2,996 (+4977.97%)
Mutual labels:  hook
Zxhookdetection
【iOS应用安全、安全攻防】hook及越狱的基本防护与检测(动态库注入检测、hook检测与防护、越狱检测、签名校验、IDA反编译分析加密协议Demo);【数据传输安全】浅谈http、https与数据加密
Stars: ✭ 241 (+308.47%)
Mutual labels:  hook
Fridacontainer
FridaContainer 整合了网上流行的和自己编写的常用的 frida 脚本,为逆向工作提效之用。 frida 脚本模块化,Java & Jni Trace。
Stars: ✭ 190 (+222.03%)
Mutual labels:  hook
use-route-as-state
Use React Router route and query string as component state
Stars: ✭ 37 (-37.29%)
Mutual labels:  hook
Qujing
曲境是一个xposed模块,可实现在PC浏览器上动态监控(hook)函数调用和查看堆栈信息,及反射调用(invoke)等功能。
Stars: ✭ 197 (+233.9%)
Mutual labels:  hook
Interface-Inspector-Hook
Interface Inspector破解
Stars: ✭ 43 (-27.12%)
Mutual labels:  hook
use-callbag
👜 Use callbag as React hook.
Stars: ✭ 34 (-42.37%)
Mutual labels:  hook
Component Size
React hook for determining the size of a component
Stars: ✭ 224 (+279.66%)
Mutual labels:  hook
Frida Skeleton
基于frida的安卓hook框架,提供了很多frida自身不支持的功能,将hook安卓变成简单便捷,人人都会的事情
Stars: ✭ 222 (+276.27%)
Mutual labels:  hook
Understand Plugin Framework
demos to help understand plugin framwork
Stars: ✭ 2,507 (+4149.15%)
Mutual labels:  hook
react-use-countdown
React hook for countdown state.
Stars: ✭ 19 (-67.8%)
Mutual labels:  hook
Xmark
A PHP7 extension that can hook most functions/classes and parts of opcodes
Stars: ✭ 209 (+254.24%)
Mutual labels:  hook
use-spring
Hooke's law hook
Stars: ✭ 53 (-10.17%)
Mutual labels:  hook
Elfhook
modify PLT to hook api, supported android 5\6.
Stars: ✭ 202 (+242.37%)
Mutual labels:  hook
Use Image Color
🎨 A hook to grab a color palette from images. Render a skeleton color while your original image still loading.
Stars: ✭ 222 (+276.27%)
Mutual labels:  hook
Funchook
Hook function calls by inserting jump instructions at runtime
Stars: ✭ 253 (+328.81%)
Mutual labels:  hook
rdeco
响应式对象编程库,从时间和空间上解耦你的代码
Stars: ✭ 54 (-8.47%)
Mutual labels:  hook
Ryder
Runtime redirection of method calls for .NET Core.
Stars: ✭ 34 (-42.37%)
Mutual labels:  hook

ideas

Ideas: making it easier to extend Python’s syntax.

ideas logo

Documentation

Everything you need will eventually be found here.

Installation

python -m pip install ideas

Depending on your OS, you might need to write python3 or py instead of python in the above.

Dependencies

Some examples, using custom encoding, bytecode transformations or AST transformations do not work with Python 3.8 and/or later versions. However, they could be adapted to work with these later versions.

Usage

Suppose that you want to use function as a keyword in Python, to mean the same thing as lambda, enabling you to write

# my_program.py

square = function x: x**2
print(f"{square(4)} is the square of 4.")

if __name__ == "__main__":
    print("This is run as the main module.")

You can do this using an import hook.

The simplest (but flawed) way to create such an import hook with ideas would be as follows:

from ideas import import_hook

def transform(source, **kwargs):
    return source.replace("function", "lambda")

import_hook.create_hook(transform_source=transform)

Then, you'd need to use it. Since there is already an example import hook that does this, we'll use it instead. All you have to do is instruct Python to add the import hook, and it will be used from that point on. There are two ways to do so.

The first method would be to create a second file which adds the required import hook and then imports your program.

# Let's call this 'loader.py'

from ideas.examples import function_keyword
function_keyword.add_hook()

import my_program

You could then run this second file the normal way.

python loader.py

So, my_program.py , and any other module that could be loaded by it would recognize that function is a valid alternative to lambda. However, using this method, loader would be the __main__ script, and the code block defined by if __name__ == "__main__": in my_program would be ignored.

The second way is to skip the creation of a loader, and run my_program directly using ideas:

python -m ideas my_program -t function_keyword

This method will ensure that my_program is the __main__ module.

Many more examples can be found in the documentation, including a better way to create such an import hook and information about a console (REPL) that supports code transformations.

Tools

This project uses black for formatting, pytest for running tests, and flake8 for linting with custom settings compatible with black.

Contact

You can either file an issue or email me at [email protected].

License

MIT

Infrequently asked questions, comments and answers

As I write (and occasionally update) this README file, nobody else knows about this project. So, it is impossible for there to be some Frequently Asked Questions. In their absence, the following imaginary dialogue has been written.

Why?

Because it is fun. If this is not enough of a justification for you, have a look at motivation which contains a longer, and possibly more serious answer.

Is it safe to use in production code?

Most probably not.

But your example works perfectly well in my code; can I use it in my project?

I don't think you should if your project is to be used by anyone else but yourself.

I found a bug.

Wonderful, please file an issue so that I can attempt to fix it. Note however that some examples are just proof of concepts and are not meant to be robust.

Can I contribute code for a new example?

Yes, please, by all means. But I suggest that you first create an issue that gives an overview of what you wish to accomplish.

I found a cool use of import hooks in another project, different from all of your examples. Could you include it?

Please, give me the details, and I will see if I can easily include a similar example and if I think it is worthwhile to do so.

I think that the explanation you have written for X could be improved upon.

Please tell me more by filing an issue first and possibly creating a pull-request afterwards.

I have an idea for a new example, but do not know how to write the code for it.

First, make sure you go through all the existing examples to confirm that none can easily be adapted to do what you want. If that is the case, file an issue ... but please don't be offended if I don't write code for it and end up closing the issue: I already have too many ideas of my own for this project, too many other projects, and not enough time to do all that I want.

That being said, I do like tinkering with import hooks ...

In file X.py, you do not respect convention Y from PEP-8. This is unacceptable in a Python project.

Seriously? This project is all about exploring potential changes to Python's syntax, some of which are downright crazy, and you complain about a PEP-8 violation? ...

Ok, perhaps you can tell me, and I will see if it makes sense to change what I wrote.

People from the Python-ideas mailing lists mentioned that I should look at this project for my idea, but I don't know where to start.

Please, have a look at the documentation. If you go through all the examples in the order that they are presented, you might learn how to implement your idea.

What about something like from __future__ import braces?

No. See Examples that will never be included.

You're no fun. Anyway, why this silly name for a project? The word "ideas" has nothing to do with import hooks in Python.

For this project, I was thinking of using importhook (singular) or importhooks (plural). However, there is already a project named importhook on Pypi and I thought that using the plural form would likely be just too confusing.

I settled on ideas as I am guessing that the main application would be for people to try out suggestions from or for python-ideas. A few days later, I came up with the above image and this cemented my highly subjective opinion that this choice of name might not such a bad idea.

Anyway, enough of this banter. If you want to know more about this project, please consult the documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].